home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Examples / Nothing / Nothing.p
Encoding:
Text File  |  1990-10-25  |  4.8 KB  |  148 lines  |  [TEXT/MPS ]

  1. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n+]}
  2. { Nothing.p }
  3. { Copyright © 1986-1990 by Apple Computer, Inc. All rights reserved.}
  4.  
  5. {[f-]}
  6. {
  7.     This is a very small sample application which can save files on disk and can
  8.     print.
  9.  
  10.     The application's windows each contain the word 'MacApp', in large type, and
  11.     are framed by a large gray border.
  12.  
  13.     Documents can be saved on disk and later reopened, but the only
  14.     document-specific information saved in the disk file is the Print information,
  15.     which means that if you set print specifications using the Page Setup dialog
  16.     for a document, and then save the document (using Save As or Save a Copy),
  17.     those specifications are saved on disk, and when you reopen the document
  18.     you will find those same print specifications holding for the document.
  19.  
  20.  
  21.     All applications that create views procedurally need to reimplement at least three
  22.     methods:
  23.  
  24.        TApplication.DoMakeDocument    --    Launches the appropriate type of Document object
  25.        TDocument.DoMakeViews        --    Launches the appropriate type of View and window objects
  26.        TView.Draw                    --    Draws the contents of a view
  27.  
  28.     This application, however, consists of the reimplementation of only one method -
  29.     TView.Draw.  This is possible since the view is created from templates;  MacApp
  30.     supplies the default 'view' resource.  So in a sense this application is the smallest
  31.     possible MacApp application.
  32. }
  33. {[f+]}
  34.  
  35. PROGRAM UNothing;
  36.  
  37.   {$MC68020-}                                            { The main program must be universal code }
  38.   {$MC68881-}
  39.  
  40.     USES
  41.         { • MacApp }
  42.         UMacApp,
  43.  
  44.         { • Building Blocks }
  45.         UPrinting,
  46.  
  47.         { • Implementation Use }
  48.         Fonts;
  49.  
  50.     CONST
  51.  
  52.         kSignature            = 'SS01';                    { Application signature}
  53.         kFileType            = 'SF01';                    { File-type code used for document files
  54.                                                           created by this application}
  55.  
  56.     TYPE
  57.  
  58.         TNothingApplication = OBJECT (TApplication)
  59.  
  60.             PROCEDURE TNothingApplication.INothingApplication(itsMainFileType: OSType);
  61.             { Initializes the application and globals. }
  62.             END;
  63.  
  64.         TDefaultView        = OBJECT (TView)
  65.  
  66.             PROCEDURE TDefaultView.Draw(area: Rect); OVERRIDE;
  67.             { Draws the view seen in the window. Every nonblank view MUST override this method. }
  68.             END;
  69.  
  70.         { I M P L E M E N T A T I O N }
  71.  
  72. {--------------------------------------------------------------------------------------------------}
  73.  
  74.     PROCEDURE TNothingApplication.INothingApplication(itsMainFileType: OSType);
  75.  
  76.         BEGIN
  77.         IApplication(itsMainFileType);
  78.  
  79.         RegisterStdType('TDefaultView', kStdDefaultView);    { So my view will be substituted when
  80.                                                             MacApp® creates the "default view".
  81.                                                             More complex documents and views will
  82.                                                             require overriding
  83.                                                             TApplication.DoMakeDocument,
  84.                                                             TDocument.DoMakeviews and (if not using
  85.                                                             template views) TDocument.DoMakeWindows. }
  86.         { So the linker doesn't dead strip class info }
  87.         IF gDeadStripSuppression THEN
  88.             IF Member(TObject(NIL), TDefaultView) THEN ;
  89.         END;
  90.  
  91. {--------------------------------------------------------------------------------------------------}
  92.  
  93.     PROCEDURE TDefaultView.Draw(area: Rect); OVERRIDE;
  94.  
  95.         VAR
  96.             itsQDExtent:        Rect;
  97.  
  98.         BEGIN
  99.         PenNormal;
  100.         PenSize(10, 10);
  101.         PenPat(dkGray);
  102.  
  103.         GetQDExtent(itsQDExtent);                        { We know its extent always fits in
  104.                                                           QuickDraw coordinates. }
  105.         FrameRect(itsQDExtent);                         { Draw a dark gray frame}
  106.  
  107.         {Set font and size for subsequent display in the window}
  108.         SetPortTextStyle(gApplicationStyle);
  109.         TextSize(72);
  110.  
  111.         InsetRect(itsQDExtent, 30, 20);
  112.         MADrawString(AtStr('MacApp®'), itsQDExtent, teJustSystem);    { Draw the word 'MacApp®' in large
  113.                                                         type using our handy international compatible
  114.                                                         DrawString substitute. }
  115.         PenNormal;                                        { Restore the pen state. }
  116.  
  117.         INHERITED Draw(area);
  118.         END;
  119.  
  120. {--------------------------------------------------------------------------------------------------}
  121.     { T H E   M A I N    P R O G R A M }
  122.  
  123.     VAR
  124.  
  125.         gNothingApplication: TNothingApplication;        { The application object }
  126.  
  127.     BEGIN
  128.     InitUMacApp(8);                                 { Initialize MacApp; 8 calls to MoreMasters
  129.                                                      We will rely on InitUMacApp automatically
  130.                                                      initializing the toolbox for us (InitToolBox)
  131.                                                      and making sure we can run in the current
  132.                                                      environment (ValidateConfiguration/StdAlert).
  133.                                                      This approach  while easier doesn't give you
  134.                                                      validation early enough for some needs.  See
  135.                                                      the other examples for alternate was.
  136.                                                      If you will be using a splash screen see the
  137.                                                      CALC example for details. }
  138.     InitUPrinting;                                    { Initialize the UPrinting unit:}
  139.  
  140.     New(gNothingApplication);                        { Allocate a new TNothingApplication
  141.                                                       object }
  142.     FailNIL(gNothingApplication);
  143.     gNothingApplication.INothingApplication(kFileType); { Initialize that new object:}
  144.  
  145.     gNothingApplication.Run;                        { Run the application. When it's done,
  146.                                                       exit.}
  147.     END.
  148.